#include <iostream>

using namespace std;

const int N = 1e6 + 10;

int cur = 1;
int e[N], ne[N];

void push_head(int x)
{
    e[cur] = x;
    ne[cur] = ne[0];
    ne[0] = cur++;
}

void insert(int k, int x)
{
    e[cur] = x;
    ne[cur] = ne[k];
    ne[k] = cur++;
}

int erase(int k)
{
    int tmp = e[ne[k]];
    ne[k] = ne[ne[k]];
    return tmp;
}

void show(void)
{
    int p = ne[0];
    while (p)
    {
        printf("%d ", e[p]);
        p = ne[p];
    }
    printf("\n");
}

int main(void)
{
    int m, k, x;
    char tmp;
    cin >> m;
    while (m--)
    {
        cin.get();
        scanf("%c%d", &tmp, &k);
        if (tmp == 'H')
            push_head(k);
        else if (tmp == 'D')
            erase(k);
        else
        {
            scanf("%d", &x);
            insert(k, x);
        }
    }
    show();
}